<template>
  <div class="home">
    <div id="main"></div>
  </div>
</template>

<script>
import * as echarts from 'echarts'
export default {
  mounted() {
    this.initCharts()
  },
  created() {
    this.setData()
  },
  data() {
    return {
      dataSet: []
    }
  },
  methods: {
    random(max) {
      return (Math.random() * max).toFixed(3)
    },
    setData() {
      for (let i = 0; i < 7; i++) {
        this.dataSet.push(this.random(5))
      }
      console.log(this.dataSet)
    },
    initCharts() {
      const myChart = echarts.init(document.getElementById('main'))
      const option = {
        // 图表定位
        grid: {
          top: 50, left: 50
        },
        title: {
          text: 'ECharts 入门示例'
        },
        tooltip: {
        },
        legend: {
          data: ['生长值1', '生长值2']
        },
        xAxis: {
          data: ['Mon', 'Tue', 'Wed', 'Thurs', 'Fri', 'Sat', 'Sun']
        },
        yAxis: {},
        series: [{
          name: '生长值1',
          type: 'line',
          data: this.dataSet
        }, {
          name: '生长值2',
          type: 'bar',
          data: this.dataSet
        }]
      }
      myChart.setOption(option)
    }
  }
}
</script>
<style scoped>
#main {
  width: 600px;
  height: 400px;
  margin: auto;
  border: 1px solid;
}
</style>
